import axios from "axios";
import {Tool} from "@/util/tool";
import {store} from "@/store";

axios.defaults.baseURL = "http://127.0.0.1:8888"
const request = axios.create({
    timeout: 5000,
    headers: {
        'Content-Type': "application/json; charset=utf-8"
    }
});

request.interceptors.request.use((config:any)=> {
    const token = store.state.user.token;
    if (Tool.isNotEmpty(token)) {
        config.headers.token = token;
    }
    return config;
}, error => {
    return Promise.reject(error);
});
request.interceptors.response.use( res=> {
    return res;
}, error => {
    return Promise.reject(error);
});

export default request;